//using System;
//using Shared;
//using HDL_ON.UI.CSS;
//using System.Collections.Generic;
//using System.Threading;
//using HDL_ON.DAL.Server;
//namespace HDL_ON.UI
//{
// ///
// /// 管理配置给音箱的设备列表
// ///
// public class SmartSpeakerSelectDevicesPage : FrameLayout
// {
// ///
// ///
// ///
// FrameLayout bodyView;
// ///
// /// 全选按钮
// ///
// Button btnChooseAll;
// ///
// /// 当前
// ///
// VerticalScrolViewLayout bodyScrolView;
// /////
// ///// 底部保存操作按钮
// /////
// //Button btnSave;
// ///
// /// 音箱参数
// ///
// SpeakerInfo speakerInfo;
// ///
// /// 设备、场景列表
// ///
// List targetInfoList = new List();
// /////
// ///// 管理当前选择选的设备、场景列表
// /////
// //List selectInfoList = new List();
// ///
// /// 当前房间的设备和场景
// ///
// List roomFunctionOrSceneList = new List();
// ///
// ///
// ///
// ///
// ///
// public SmartSpeakerSelectDevicesPage(SpeakerInfo speakerInfo, List roomFunctionOrSceneList)
// {
// bodyView = this;
// bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
// this.speakerInfo = speakerInfo;
// this.roomFunctionOrSceneList = roomFunctionOrSceneList;
// }
// ///
// ///
// ///
// public void LoadPage()
// {
// new TopViewDiv(bodyView, Language.StringByID(StringId.DataManagement)).LoadTopView();
// //顶部全选按钮
// var allRoomView = new FrameLayout()
// {
// Y = Application.GetRealHeight(64),
// Height = Application.GetRealHeight(50),
// BackgroundColor = CSS_Color.MainBackgroundColor,
// };
// bodyView.AddChidren(allRoomView);
// Button btnAllRoomText = new Button()
// {
// X = Application.GetRealWidth(16),
// Width = Application.GetRealWidth(280),
// TextID = StringId.SelectedAll,
// TextSize = CSS_FontSize.SubheadingFontSize,
// TextColor = CSS_Color.FirstLevelTitleColor,
// TextAlignment = TextAlignment.CenterLeft,
// };
// allRoomView.AddChidren(btnAllRoomText);
// btnChooseAll = new Button()
// {
// X = Application.GetRealWidth(331),
// Gravity = Gravity.CenterVertical,
// Width = Application.GetMinRealAverage(28),
// Height = Application.GetMinRealAverage(28),
// UnSelectedImagePath = "Public/ChooseIcon.png",
// SelectedImagePath = "Public/ChooseOnIcon.png",
// IsSelected = true,
// };
// allRoomView.AddChidren(btnChooseAll);
// allRoomView.AddChidren(new Button()
// {
// Gravity = Gravity.CenterHorizontal,
// Y = Application.GetRealHeight(49),
// Height = Application.GetMinReal(1),
// Width = Application.GetRealWidth(343),
// BackgroundColor = CSS_Color.DividingLineColor,
// });
// bodyScrolView = new VerticalScrolViewLayout()
// {
// Y = allRoomView.Bottom,
// Height = Application.GetRealHeight(450),
// };
// bodyView.AddChidren(bodyScrolView);
// var btnSave = new ConfirmButton()
// {
// Y = Application.GetRealHeight(519 + 64),
// TextID = StringId.Save
// };
// bodyView.AddChidren(btnSave);
// //全选按钮点击事件
// LoadEvent_AllSharedDataChange(allRoomView, btnChooseAll);
// LoadEvent_Save(btnSave);
// GetDeviceAndSceneList();
// }
// ///
// /// 全选按钮点击事件
// ///
// void LoadEvent_AllSharedDataChange(FrameLayout allRoomView, Button btnChooseAll)
// {
// EventHandler eventHandler = (sender, e) =>
// {
// btnChooseAll.IsSelected = !btnChooseAll.IsSelected;
// if(selectInfoList == null)
// {
// selectInfoList = new List();
// }
// if (btnChooseAll.IsSelected)
// {
// foreach (var info in roomFunctionOrSceneList)
// {
// selectInfoList.Add(info);
// }
// }
// RefreshListView();
// };
// btnChooseAll.MouseUpEventHandler = eventHandler;
// allRoomView.MouseUpEventHandler = eventHandler;
// }
// ///
// /// 保存按钮点击事件
// ///
// ///
// void LoadEvent_Save(Button btnSave)
// {
// EventHandler eventHandler = (sender, e) =>
// {
// AddDevicesSceneList(targetInfoList);
// };
// btnSave.MouseUpEventHandler = eventHandler;
// }
// ///
// ///
// ///
// ///
// void AddDevicesSceneList(List updateList)
// {
// var waitPage = new Loading();
// bodyView.AddChidren(waitPage);
// waitPage.Start(Language.StringByID(StringId.PleaseWait));
// System.Threading.Tasks.Task.Run(() =>
// {
// try
// {
// var updateSpeakerDeviceListObj = new UpdateSpeakerDeviceListObj()
// {
// homeId = speakerInfo.homeId,
// tokenId = speakerInfo.tokenId,
// targetInfos = updateList
// };
// var revertObj = new HttpServerRequest().UpdateSpeakerDeviceList(updateSpeakerDeviceListObj);
// if (revertObj.Code == StateCode.SUCCESS)
// {
// Application.RunOnMainThread(() =>
// {
// //保存成功、页面关闭
// Utlis.ShowTip(Language.StringByID(StringId.SavedSuccessfully));
// if (bodyView != null)
// {
// bodyView.RemoveFromParent();
// }
// });
// }
// else
// {
// //提示错误
// IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
// }
// }
// catch
// {
// }
// finally
// {
// Application.RunOnMainThread(() =>
// {
// if (waitPage != null)
// {
// waitPage.RemoveFromParent();
// waitPage = null;
// }
// });
// }
// });
// }
// ///
// /// 加载房间的设备和场景列表
// ///
// void GetDeviceAndSceneList()
// {
// bodyScrolView.RemoveAll();
// var waitPage = new Loading();
// bodyView.AddChidren(waitPage);
// waitPage.Start(Language.StringByID(StringId.PleaseWait));
// System.Threading.Tasks.Task.Run(() =>
// {
// try
// {
// var revertObj = new HttpServerRequest().GetSpeakerDeviceList(0, speakerInfo.tokenId);
// if (revertObj.Code == StateCode.SUCCESS)
// {
// var list = Newtonsoft.Json.JsonConvert.DeserializeObject>(revertObj.Data.ToString());
// Application.RunOnMainThread(() => {
// if (list != null && list.Count > 0)
// {
// targetInfoList = list;
// }
// else
// {
// targetInfoList = new List();
// }
// RefreshListView();
// });
// }
// else
// {
// //提示错误
// IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
// }
// }
// catch
// {
// }
// finally
// {
// Application.RunOnMainThread(() =>
// {
// if (waitPage != null)
// {
// waitPage.RemoveFromParent();
// waitPage = null;
// }
// });
// }
// });
// }
// ///
// ///
// ///
// void RefreshListView()
// {
// bodyScrolView.RemoveAll();
// if (roomFunctionOrSceneList == null) return;
// foreach (var roomData in roomFunctionOrSceneList)
// {
// AddRowView(roomData);
// }
// }
// ///
// ///
// ///
// ///
// void AddRowView(SpeakerTargetInfo info)
// {
// var roomView = new FrameLayout()
// {
// Height = Application.GetRealHeight(50),
// BackgroundColor = CSS_Color.MainBackgroundColor,
// Tag = "row"
// };
// bodyScrolView.AddChidren(roomView);
// Button btnRoomText = new Button()
// {
// X = Application.GetRealWidth(16),
// Width = Application.GetRealWidth(280),
// TextSize = CSS_FontSize.SubheadingFontSize,
// TextColor = CSS_Color.FirstLevelTitleColor,
// TextAlignment = TextAlignment.CenterLeft,
// Text = info.targetName,
// };
// roomView.AddChidren(btnRoomText);
// Button btnChoose = new Button()
// {
// X = Application.GetRealWidth(331),
// Gravity = Gravity.CenterVertical,
// Width = Application.GetMinRealAverage(28),
// Height = Application.GetMinRealAverage(28),
// UnSelectedImagePath = "Public/ChooseIcon.png",
// SelectedImagePath = "Public/ChooseOnIcon.png",
// Tag = "ChooseIcon"
// };
// roomView.AddChidren(btnChoose);
// var targetData = selectInfoList.Find((obj) => obj.targetId == info.targetId);
// if (targetData != null)
// {
// btnChoose.IsSelected = true;
// //刷新属于当前房间的分享统计
// //funs_New.Add(shareData);
// }
// else
// {
// if (btnChooseAll.IsSelected)
// btnChooseAll.IsSelected = false;
// }
// var btnLine = new Button()
// {
// Gravity = Gravity.CenterHorizontal,
// //Y = Application.GetRealHeight(49),
// Height = Application.GetRealHeight(1),
// Width = Application.GetRealWidth(343),
// BackgroundColor = CSS_Color.DividingLineColor,
// };
// bodyScrolView.AddChidren(btnLine);
// EventHandler eventHandler = (sender, e) =>
// {
// btnChoose.IsSelected = !btnChoose.IsSelected;
// var sd = selectInfoList.Find((obj) => obj.targetId == info.targetId);
// if (btnChoose.IsSelected)
// {
// try
// {
// if (null == sd)
// {
// selectInfoList.Add(info);
// }
// btnChooseAll.IsSelected = true;
// foreach (var f in roomFunctionOrSceneList)
// {
// if (selectInfoList.Find((obj) => obj.targetId == f.targetId) == null)
// {
// btnChooseAll.IsSelected = false;
// break;
// }
// }
// }
// catch (Exception ex)
// {
// MainPage.Log($"Evhaaa {ex.Message}");
// }
// }
// else
// {
// if (null != sd)
// {
// selectInfoList.Remove(sd);
// }
// btnChooseAll.IsSelected = false;
// }
// };
// btnChoose.MouseUpEventHandler = eventHandler;
// roomView.MouseUpEventHandler = eventHandler;
// btnRoomText.MouseUpEventHandler = eventHandler;
// }
// }
//}